﻿// JScript 文件
    /*
    nTotalCount:总的记录数
    nShowPages
    g_PageSize：每页显示的记录数
    g_PageIndex:当前所属页数
    pagecount:总页数
    */
// JScript 文件
//获取分页
function funGetPaginationHtml()
{
    this.GetPaginationHtml=function( nTotalCount,g_PageSize,g_PageIndex,eventName)
    {
        var tHtml = '';
        //var nStartPage = Math.round(nShowPages / 2 - 0.5);
        //总页数
        var cPageCount = funGetHowManyPageCount(nTotalCount);
        var prepage=isFirstPage(g_PageIndex);
        var nextpage=islastPage(g_PageIndex,cPageCount);
        if( cPageCount > 1 )
        {
            //开始页        
            var cStartPageIndex = 1;
            //结束页
            var cEndPageIndex = cPageCount;
//            
//            var starthtm='';
//            var endhtm='';
//            if( cPageCount > nShowPages )
//            { 
//                if( ( g_Page - nStartPage ) > 1 )
//                {  
//                 cStartPageIndex = g_Page - nStartPage; 
//                   if(  cStartPageIndex-1 >1)
//                   {
//                    starthtm='&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
//                    starthtm+='&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page-1)+')">...</span>';
//                   }
//                   else
//                   {
//                    starthtm='&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
//                   }
//                   
//                }
//                if( ( cStartPageIndex + nShowPages - 1 ) < cPageCount )
//                {   
//                     cEndPageIndex = cStartPageIndex + nShowPages - 1;
//                      if( cPageCount-cEndPageIndex>1 )
//                     { 
//                        endhtm='&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page+1)+')">...</span>';
//                        endhtm+='&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'('+cPageCount+')">'+cPageCount+'</span>';
//                     }
//                     else
//                     {
//                        endhtm='&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'('+cPageCount+')">'+cPageCount+'</span>';
//                     }
//                }
//                else
//                { 
//                
//                    if( ( cEndPageIndex - nShowPages + 1 ) > 0 
//                       && ( cEndPageIndex - nShowPages + 1 ) < cStartPageIndex 
//                       ){
//                           cStartPageIndex = cEndPageIndex - nShowPages + 1;
//                       }
//                   if(  cStartPageIndex-1 >1)
//                   {
//                    starthtm='&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
//                    starthtm+='&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page-1)+')">...</span>';
//                   }
//                   else
//                   {
//                    starthtm='&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
//                   }
//                   
//                }
//            } 
            tHtml +='<div><table width="95%" border="0" cellspacing="0" cellpadding="0"><tr height=22px>';
            //首页
            tHtml +='<td width="50%" align="left">';
            tHtml +='&nbsp;<img src="images/bt_sy.gif" onclick="'+eventName+'(1)" style="cursor:pointer;" />&nbsp;';
            //分格
             //上一页
            if (g_PageIndex==1)
            {
                tHtml +='&nbsp;<img src="images/bt_sy2.gif" onclick="'+eventName+'('+prepage+')" style="cursor:pointer;"/>&nbsp;';
            }
            else
            {
                tHtml +='&nbsp;<img src="images/bt_sy2.gif" onclick="'+eventName+'('+prepage+')" style="cursor:pointer;"/>&nbsp;';
            }
            //下一页

            if (g_PageIndex==cPageCount)
            {
                tHtml +='&nbsp;<img src="images/bt_xy.gif" onclick="'+eventName+'('+nextpage+')" style="cursor:pointer;"/>&nbsp;';
            }
            else
            {
                tHtml +='&nbsp;<img src="images/bt_xy.gif" onclick="'+eventName+'('+nextpage+')" style="cursor:pointer;"/>&nbsp;';
            }
            //尾页
            tHtml +='&nbsp;<img src="images/bt_my.gif" onclick="'+eventName+'('+cPageCount+')" style="cursor:pointer;"/>&nbsp;</td>';
            //分格
            tHtml +='<td align="right">';
            //分格
            //tHtml +='<td width=3px></td>';
            //GO
            //tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            //tHtml +='&nbsp;<a href="javascript:void(0)" onclick="showPageByNum()">GO</a>&nbsp;</td>';
            //分格
            var cIndex = (cStartPageIndex)
            tHtml+='<span id="msg">共'+nTotalCount+'条记录，每页'+g_PageSize+'条　当前第'+g_PageIndex+'/'+cPageCount+'页</span>';
            tHtml+='<span >&nbsp;&nbsp;跳到第<select id="page1" name="menu1" onchange="jump()">';
            for( cIndex; cIndex < cEndPageIndex+1;cIndex++ )
             {
                if(cIndex==g_PageIndex)
                {
                    tHtml+='<option selected="true">'+cIndex+'</option>';
                }
                else
                {
                    tHtml+='<option>'+cIndex+'</option>';
                }
             }
             tHtml+='</select>页</span>';
            tHtml+='</td></tr></table></div>';
            //总页
            //tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            //tHtml +='&nbsp;&nbsp;'+g_Page+'/'+cPageCount+'页&nbsp;&nbsp;</td>';                        
        }    

        return tHtml;
    }
}
//检查是否录入数字
function   checktxt(point){   
      var   str   =  document.getElementById(point.id).value;   
      var   reg   =   new   RegExp("(^[1-9]+[0-9]*$)"); 
      if(!reg.test(str))
      {
      alert("请输入大于0的整数");
      document.getElementById(point.id).value="";
      //document.getElementById(point.id).value=str.substr(0,str.length-1);
      }
      if (event.keyCode==13)
      {
        showPageByNum();
      }
  }
  
function changeColor(pointer,cs){
    if(cs==1){
        pointer.style.color="red";
    }else{
        pointer.style.color="blue";
    }
}
       
function isFirstPage(page)
{    
   var page=((page-1)>0)?(page-1):1;
   return page;
}
function islastPage(page,pagecount)
{
   var page = ( parseInt(page) + 1 > pagecount) ? pagecount : parseInt(page) + 1;
   return page;
}

///通过总记录数计算总共的页数
function funGetHowManyPageCount( nTotalCount )
{
    if( nTotalCount <=0 )
    {
        return 0;
    }
    else
    {
        var tPageCount = 0;
        if( ( nTotalCount %g_PageSize ) == 0)
        {
            tPageCount = nTotalCount / g_PageSize;
        }
        else
        {
            tPageCount = Math.ceil( nTotalCount / g_PageSize );
        } 
        return tPageCount;
    }
}


function jump()
{
    var page=document.getElementById("page1");
     var values = page[page.selectedIndex].innerHTML;
    goToPage(values);
    var slength = document.getElementById("page1").options.length;
    for(var i=0;i<slength;i++){
            if(document.getElementById("page1").options[i].innerHTML==values){
                    document.getElementById("page1").options[i].selected=true;
            }
    }

}

